-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
estuary-cdk: allow a cron expression to re-initialize a binding's state #2437
Conversation
ResourceConfig
to allow a cron expression to re-initialize a binding's state on a schedule078f402
to
02ec872
Compare
First I'll recognize that I'm pretty sure my initial suggestion was this ^, so I'm totally backtracking. But I am wondering if you think it would be much effort to make it work the other way, where an ongoing backfill is allowed to complete first? As I've thought about it more than might be a better experience, in cases where a backfill takes so long it would be best to at least get it done before it starts again. But if it would be a lot more effort, the way it is in the PR now is probably fine, and would match our backfill script behavior anyway. |
No, I actually think it'll be pretty easy to update. It'll just be an extra condition to check if |
Another high-level thought: Other than the initial connector startup, I'm not seeing anywhere that it would know that it has crossed the threshold for triggering a new backfill. Connectors using the CDK restart every 24 hours so it would check at least that often, but if an interval more like "every 2 hours" is selected that won't work very well, nor will it work well for a case like "every Friday at 9 PM", since the connector could do its 24-hour restart at 8:59 PM and then not restart again until almost 24 hours later. I think we'd need to do something like upon opening, start up a coroutine that will set the |
That sounds like the right direction. It does feel like it conflicts a little with the goal of allowing existing backfills to finish, but we can avoid reinitializing after start up if there's still a backfill that needs to complete. I'll work on doing something like that. I think whether or not on-going backfills check the That said, I still think it makes sense to use |
02ec872
to
221f984
Compare
I've updated per our discussion. Changes include:
I've confirmed:
I kept the "scheduled backfills take precedence over ongoing backfills" behavior. Like you mentioned, the connector would need to somehow know when an ongoing backfill completes to faithfully keep to a schedule & begin a new backfill if it skipped any scheduled ones. That scope could be done in the future if needed. It's also worth noting that although |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This commit gets a few failing capture snapshots to pass before I make changes that could impact CDK connectors.
…re-initializing a resource's state on a schedule For a couple capture connectors, bindings need backfilled on some schedule. So far, we've been manually backfilling these bindings every day/week, and it would be nice if a resource config level setting existed to automatically backfill. This commit extends the existing `ResourceConfig` with the `ResourceConfigWithSchedule` class, allowing resources to specify a schedule for their state to be re-initialized (i.e backfill the binding). This schedule must either be an empty string or a valid cron expression accepted by `pycron`. In order to know when a binding's state was last initialized, the `last_initialized` property has been added to all bindings' states. Since the resource config is the same for all bindings in a connector, a connector that needs to use `ResourceConfigWithSchedule` for at least one binding must use it for all bindings. `pycron` was chosen as the cron package for a few reasons: - The typically clear choice for a Python cron package `croniter` may be unpublished from PyPI in the near future due to the maintainer's concerns around EU CRA laws & liabilities. It is not clear that a different maintainer will take over & keep `croniter` available, and beyond forking & maintaining our own `croniter` repo, I don't see a longterm solution to using that package in our code. - `pycron` has the minimal functionality we need & appears to be somewhat actively maintained & used by others. If there are bindings with cron schedules, we spawn a coroutine to stop the connector at the soonest future scheduled re-initialzation time to adhere to the bindings' schedules relatively closely.
Since the CDK now uses `pycron`, the lock files for connectors using estuary-cdk need updated to include `pycron` as a dependency.
…use `ResourceConfigWithSchedule` Due to Braintree's limitation of only allowing queries for `credit_card_verifications`, `customers`, `disputes`, and `subscriptions` to filter based on their created_at datetime, we can't incrementally capture updates to previously created data. We've been manually backfilling these bindings every week, but now we can use the new `ResourceConfigWithSchedule` resource config to set a schedule for these bindings to automatically rebackfill. I set the default schedule for these bindings to backfill every Friday at 8:00 PM UTC, which seems like a reasonable setting for most use cases that would prefer to perform possibly lengthy backfills over the weekend.
221f984
to
ba1594a
Compare
Description:
Background
For a couple capture connectors, bindings need backfilled on some schedule. So far, we've been manually backfilling these bindings every day/week. It would be nice if a resource config level setting existed to automatically backfill on a schedule based on a cron expression, like described in this issue for our batch SQL captures.
Scope
This PR's scope includes:
ResourceConfig
with theResourceConfigWithSchedule
class, allowing resources to specify a schedule for their state to be re-initialized (i.e backfill the binding). This schedule must either be an empty string or a valid cron expression accepted bypycron
.last_initialized
property to all bindings' states for all connectors.source-braintree-native
to useResourceConfigWithSchedule
for its incremental bindingsAdditional Details
Since the resource config is the same for all bindings in a connector, a connector that needs to use
ResourceConfigWithSchedule
for at least one binding must use it for all bindings.pycron
was chosen as the cron package for a few reasons:croniter
may be unpublished from PyPI in the near future due to the maintainer's concerns around EU CRA laws & liabilities. It is not clear that a different maintainer will take over & keepcroniter
available, and beyond forking & maintaining our owncroniter
repo, I don't see a long term solution to using that package in our code.pycron
has the minimal functionality we need & appears to be somewhat actively maintained & used by others.Scheduled backfills take precedence over ongoing backfills. If users want backfills to complete before the next scheduled backfill starts, they'll need to update the binding's schedule to have longer intervals between backfills.
Workflow steps:
Schedules are configured per binding in the resource config using a valid cron expression. If a binding's state should be re-initialized per its schedule, it will do so on the next connector restart.
Documentation links affected:
Docs for
source-braintree-native
should be updated to reflect:schedule
setting for bindings.transactions
. These are enabled by default for the connector & can be updated by the users themselves if needed.Notes for reviewers:
Tested on a local stack. Confirmed:
state.last_initialized
to existing captures works & does not cause connector failures.ResourceConfig
toResourceConfigWithSchedule
works & does not cause connector failures.schedule
causes the binding's state to be re-initialized per that specific schedule.This change is